<?php

namespace App\Http\Controllers\Api;

use App\Token;
use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{

    public function checktoen($token)
    {

        $model =Token::check($token);


        return $model;
    }
    /**
     * 微信登录
     * @return int
     */
    public function login(Request $request)
    {

        if ($request->isMethod('post')) {


            $map = $request->input();

            //查找是否存在该用户
            $model = User::Login($map);

            return $this->response->array([
                'status_code'=>200,
                'message'=>'登录成功',
                'data'=>$model,
            ]);
        }
    }

    public function GetUserInfo(Request $request)
    {

        $token = $request->input('token');

        //检验token
        $uid = $this->checktoen($token);

        if($uid ==400){
            return $this->response->array([
                'status_code'=>400,
                'message'=>'token失效',
            ]);

        }
        if($uid==401){
            return $this->response->array([
                'status_code'=>400,
                'message'=>'token失效',
            ]);
        }
        //获取用户信息
        $user = User::where('id',$uid)->first();
        return $this->response->array([
            'message'=>'获取用户信息成功',
            'status_code'=>200,
            'data'=>$user
        ]);
    }
}
